package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import service.PermissionService;

import java.util.List;

/**
 * 包名:  com.iteitan.service.impl;
 * 作者:  Eitan
 * 日期:  2019/9/9 20:15
 * 权限管理服务接口的实现类
 */
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;
    /**
     * 添加权限
     * @param permission
     */
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    /**
     * 根据id删除权限
     * @param id
     * @return
     */
    @Override
    public void deleteById(Integer id) {
        permissionDao.deleteById(id);
    }

    /**
     * 权限分页
     * @param currentPage
     * @param pageSize
     * @param queryString
     * @return
     */
    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<Permission> page= permissionDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 编辑权限
     * @param permission
     */
    @Override
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    /**
     * 查询权限
     * @param id
     * @return
     */
    @Override
    public Permission findPermissionById(Integer id) {
        return permissionDao.findPermissionById(id);
    }

    /**
     * 根据角色id查找拥有的权限ids
     * @param id
     * @return
     */
    @Override
    public List<Integer> findPermissionIdsByRoleId(int id) {

        return permissionDao.findPermissionIdsByRoleId(id);
    }


}
